<template>
    <Card dis-hover :bordered="false">
        <jg-Search
            :searchData="searchData"
            @click="guideopenedit"
            @on-enter-input="askDatakeyword"
            @on-clear-input="askDatakeyword"
            @on-enter-inputs="askDatakeywords"
            @on-clear-inputs="askDatakeywords"
            @on-change-change="askDatanow"
            @on-change-date="askDataing"
        ></jg-Search>
        <div class="i-table-no-border">
            <Table
                highlight-row
                ref="table"
                :columns="columns"
                :loading="loading"
                :data="data">
                <template slot="basic" slot-scope="{ row }">
                    <span
                    ><Icon
                        style="color: #19be6b;"
                        v-if="+row.is_guide_create === 1"
                        type="ios-body"
                    ></Icon>
                        {{ row.user_name }} {{ row.gender_str }}
                        {{ row.age }}岁</span
                        >
                </template>
                <template slot="patient_card_id" slot-scope="{ row }">
                    <div v-if="!row.is_edit">{{row.patient_card_id}}</div>
                    <Input v-else v-model="row.patient_card_id" @on-keyup="row.patient_card_id=row.patient_card_id.replace(/\s+/g,'')"></Input>
                </template>
                <template slot="clinic_id" slot-scope="{ row }">
                    <div v-if="!row.is_edit">{{row.clinic_name}}</div>
                    <Select v-else v-model="row.clinic_id">
                        <Option v-for="item in condition.clinic" :value="item.value" :key="item.value">{{ item.label }}</Option>
                    </Select>
                </template>
                <template slot="mobile" slot-scope="{ row }">
                    <div v-for="(item, index) of row.mobile" :key="index">
                        <p>{{ item }}</p>
                    </div>
                </template>
                <template slot="disease" slot-scope="{ row }">
                    <span>{{
                        row.child_diseases_name || row.diseases_name
                    }}</span>
                </template>
                <template slot="status_name" slot-scope="{ row }">
                    <Badge
                        v-if="row.status_name === '到诊'"
                        status="success"
                        :text="row.status_name"
                    ></Badge>
                    <Badge
                        v-else-if="row.status_name === '预约'"
                        status="processing"
                        :text="row.status_name"
                    ></Badge>
                    <Badge
                        v-else-if="row.status_name === '跟进中'"
                        status="warning"
                        :text="row.status_name"
                    ></Badge>
                    <Badge
                        v-else-if="row.status_name"
                        status="default"
                        :text="row.status_name"
                    ></Badge>
                </template>
                <template slot-scope="{ row }" slot="info">
                    <a class="ivu-ml-8"
                       v-hasC="{
                           name: 'patient-index-arrive',
                           flag: 'v1/patient/index/arrive',
                       }"
                       v-if="+row.op_type === 1"
                       @click="handleOpenDrawer(row)"
                       :disabled="disabled"
                    >到诊</a>
                    <a class="Warning ivu-ml-8"
                       v-hasC="{
                           name: 'patient-index-cancel-arrive2',
                           flag: 'v1/patient/index/cancel-arrive',
                       }"
                       v-else-if="+row.op_type === 2"
                       @click="handleRemove(row)"
                       :disabled="disabled"
                    >撤诊</a>
                    <a
                        v-hasC="{
                            name: 'v1-patient-index-guide-del',
                            flag: 'v1/patient/index/guide-del',
                        }"
                        class="Error ivu-ml-8"
                        v-else-if="+row.op_type === 0"
                        @click="handleRemoves(row)"
                        :disabled="disabled"
                    >删除</a>
                    <a
                        class="blue ivu-ml-8"
                        v-if="!row.is_edit"
                        :disabled="disabled"
                        @click="row.is_edit = true, disabled = true"
                    >编辑</a>
                    <a
                        class="Success ivu-ml-8"
                        v-if="row.is_edit"
                        @click="handleSub(row)"
                    >保存</a>
                    <a
                        class="SubColor ivu-ml-8"
                        v-if="row.is_edit"
                        @click="row.is_edit = false, disabled = false"
                    >取消</a>
                </template>
            </Table>
            <div class="ivu-mt ivu-text-center">
                <Page
                    show-total
                    show-elevator
                    show-sizer
                    :total="total"
                    :current.sync="params.page"
                    :page-size="params.pageSize"
                    :page-size-opts="pageOpts"
                    @on-change="changepage"
                    @on-page-size-change="changepageSize"
                ></Page>
            </div>
            <Modal
                v-model="modal"
                title="到诊确认"
                :mask-closable="false"
                @on-cancel="handleDrawerCancel('formItems')">
                <Form
                    :model="formItems"
                    ref="formItems"
                    :label-width="100"
                    :rules="createRules"
                >
                    <FormItem label="基本信息"
                    >{{ daozhenlist.user_name }}
                        {{ daozhenlist.gender_str}}
                        {{ daozhenlist.age }}岁</FormItem
                        >
                    <FormItem label="手机号：">{{
                        daozhenlist.mobile
                    }}</FormItem>
                    <FormItem label="备注：">{{ daozhenlist.remark }}</FormItem>
                    <FormItem label="选择诊室" prop="clinic_id">
                        <Select v-model="formItems.clinic_id">
                            <Option
                                :value="item.value"
                                v-for="item in condition.clinic"
                                :key="item.value"
                            >{{ item.label }}</Option
                            >
                        </Select>
                    </FormItem>
                    <FormItem label="诊疗号" prop="patient_card_id">
                        <Input
                            v-model="formItems.patient_card_id"
                            v-width="150"
                            placeholder="请输入患者诊疗号"
                        ></Input>
                    </FormItem>
                    <FormItem label="到诊时间" prop="revisiting_time">
                        <DatePicker :editable="false"
                                    v-model="formItems.revisiting_time"
                                    :options="options"
                                    type="date"
                                    v-width="150"
                        ></DatePicker>
                    </FormItem>
                    <FormItem label="真实姓名" prop="user_name">
                        <Input
                            v-model="formItems.user_name"
                            v-width="150"
                            placeholder="请输入真实姓名"
                        ></Input>
                    </FormItem>
                    <FormItem label="居住城市">
                        <!-- <Select
                            v-model="formItems.city_id"
                            placeholder="请输入城市拼音简写"
                            filterable
                            remote
                            clearable
                            :remote-method="remoteMethod"
                            :loading="loadingcity"
                        >
                            <Option
                                v-for="item in optionscity"
                                :key="item.value"
                                :value="item.key"
                                >{{ item.label }}</Option
                            >
                        </Select> -->
                        <jgcheckcity ref="checkcitys" @cityvalue="cityvalues" v-model="city_ids" name="guidecompletes"></jgcheckcity>
                    </FormItem>
                </Form>
                <div slot="footer">
                    <Button @click="handleDrawerCancel('formItems')"
                    >取消</Button
                    >
                    <Button
                        type="primary"
                        :loading="remarksloading"
                        @click="handleSubmit('formItems')"
                    >确定</Button
                    >
                </div>
            </Modal>
            <Modal
                v-model="showedit"
                title="登记患者"
                :mask-closable="false"
                @on-cancel="canceledit('formItem')">
                <Form
                    :model="formItem"
                    ref="formItem"
                    :label-width="120"
                    :rules="createRules"
                >
                    <FormItem prop="user_name" label="患者姓名：">
                        <Input
                            v-model="formItem.user_name"
                            placeholder="请输入患者姓名"
                        ></Input>
                    </FormItem>
                    <FormItem prop="gender" label="性别：">
                        <RadioGroup v-model="formItem.gender">
                            <Radio label="1">男</Radio>
                            <Radio label="2">女</Radio>
                        </RadioGroup>
                    </FormItem>
                    <FormItem prop="mobile" label="患者手机号：">
                        <Input v-model="formItem.mobile" placeholder="请输入患者手机号" ></Input>
                    </FormItem>
                    <FormItem label="生日：">
                        <DatePicker :editable="false"
                                    type="date"
                                    placeholder="出生年份"
                                    :options="options"
                                    v-model="formItem.birthday"
                                    style="width: 180px;"
                                    @on-change="dateage(formItem.birthday)"
                        ></DatePicker>
                    </FormItem>
                    <FormItem label="年龄：" prop="age">
                        <InputNumber
                            v-width="100"
                            v-model="formItem.age"
                            :min="1"
                            @on-change="inputage(formItem.age)"
                            placeholder="年龄"
                        ></InputNumber>
                    </FormItem>
                    <FormItem label="来源" >
                        <Row>
                            <Col span="11">
                            <FormItem prop="channel_id">
                                <Select v-model="formItem.channel_id" placeholder="请选择一级来源" @on-change="changechannel">
                                    <Option
                                        :value="item.value"
                                        v-for="item in condition.source_channel"
                                        :key="item.value"
                                    >{{ item.label }}</Option
                                    >
                                </Select>
                            </FormItem>
                            </Col>
                            <Col :offset="2" span="11" v-if="source_channellist.length>0">
                            <FormItem prop="subdivided_channels_id">
                                <Select v-model="formItem.subdivided_channels_id" placeholder="请选择二级来源">
                                    <Option
                                        :value="item.value"
                                        v-for="item in source_channellist"
                                        :key="item.value"
                                    >{{ item.label }}</Option
                                    >
                                </Select>
                            </FormItem>
                            </Col>
                        </Row>
                    </FormItem>
                    <FormItem label="居住城市">
                        <!-- <Select
                            v-model="formItem.city_id"
                            placeholder="请输入城市拼音简写"
                            filterable
                            remote
                            clearable
                            :remote-method="remoteMethod"
                            :loading="loadingcity"
                        >
                            <Option
                                v-for="item in optionscity"
                                :key="item.value"
                                :value="item.key"
                                >{{ item.label }}</Option
                            >
                        </Select> -->
                        <jgcheckcity ref="checkcity" @cityvalue="cityvalue" v-model="city_id" name="guidecomplete"></jgcheckcity>
                    </FormItem>
                    <FormItem label="诊室" prop="clinic_id">
                        <Select v-model="formItem.clinic_id">
                            <Option
                                :value="item.value"
                                v-for="item in condition.clinic"
                                :key="item.value"
                            >{{ item.label }}</Option
                            >
                        </Select>
                    </FormItem>
                    <FormItem label="诊疗号" prop="patient_card_id">
                        <Input
                            v-model="formItem.patient_card_id"
                            v-width="150"
                            placeholder="请输入患者诊疗号"
                        ></Input>
                    </FormItem>
                    <FormItem label="病种选择" required>
                        <Row>
                            <Col span="11">
                            <FormItem prop="patient_diseases_id">
                                <Select v-model="formItem.patient_diseases_id" placeholder="请选择一级病种" @on-change="changechilddiseases">
                                    <Option
                                        :value="item.value"
                                        v-for="item in patientdiseasesList"
                                        :key="item.value"
                                    >{{ item.label }}</Option
                                    >
                                </Select>
                            </FormItem>
                            </Col>
                            <Col :offset="2" span="11" v-if="childdiseasesList.length>0">
                            <FormItem prop="patient_diseases_child_id">
                                <Select v-model="formItem.patient_diseases_child_id" placeholder="请选择二级病种">
                                    <Option
                                        :value="item.value"
                                        v-for="item in childdiseasesList"
                                        :key="item.value"
                                    >{{ item.label }}</Option
                                    >
                                </Select>
                            </FormItem>
                            </Col>
                        </Row>
                    </FormItem>
                    <FormItem label="备注：">
                        <Input
                            type="textarea"
                            v-model="formItem.remark"
                            placeholder="请输入备注："
                        ></Input>
                    </FormItem>
                </Form>
                <div slot="footer">
                    <Button @click="canceledit('formItem')">取消</Button>
                    <Button
                        type="primary"
                        :loading="subloading"
                        @click="submitedit('formItem')"
                    >确定</Button
                    >
                </div>
            </Modal>
        </div>
    </Card>
</template>

<script>
    import jgSearch from '@/components/search';
    // import jgcheckcity from '@/components/checkcity';
    import mixins from '@/mixins/mixins';
    import dayjs from 'dayjs';
    import {
        patientindexguidearrivelist,
        patientindexguidecreate,
        patientindexarrive,
        patientindexcancelarrive,
        patientindexsearchcity,
        patientindexguidedel,
        patientindexeditguideuser,
        guidecreateCondition
    } from '@api/hqapi';
    export default {
        /*  import引入的组件注入到components对象中使用  */
        components: { jgSearch },
        mixins: [mixins],
        data() {
            return {
                loadingcity: false,
                disabled: false,
                optionscity: [],
                remarksloading: false,
                source_channellist: [],
                diseaseslist: [],
                patientdiseasesList: [],
                childdiseasesList: [],
                searchData: {
                    project: [
                        {
                            id: 1,
                            key: 'DatePicker',
                            style: { width: '200px' },
                            value: [new Date(), new Date()],
                            type: 'daterange',
                            options: {
                                disabledDate(date) {
                                    return (
                                        date &&
                                        date.valueOf() >
                                        Date.now()
                                    );
                                }
                            },
                            callback: 'date',
                            placeholder: '请选择已到日期'
                        },
                        {
                            id: 2,
                            key: 'TreeSelect',
                            style: { width: '118px' },
                            value: '',
                            field: { value: 'value', label: 'label' },
                            childList: [],
                            clearable: 'clearable',
                            type: 'daterange',
                            callback: 'change',
                            placeholder: '请选择病种'
                        },
                        {
                            id: 3,
                            key: 'Input',
                            style: { width: '260px' },
                            value: '',
                            placeholder: '请输入患者姓名/手机号/微信号',
                            clearable: true,
                            callback: 'input'
                        },
                        {
                            id: 4,
                            key: 'Input',
                            style: { width: '180px' },
                            value: '',
                            placeholder: '请输入诊疗号',
                            clearable: true,
                            callback: 'inputs'
                        },
                        {
                            id: 5,
                            key: 'TreeSelect',
                            style: { width: '118px' },
                            value: '',
                            field: { value: 'value', label: 'label' },
                            childList: [],
                            clearable: 'clearable',
                            type: 'daterange',
                            callback: 'change',
                            placeholder: '请选择渠道'
                        },
                        {
                            id: 6,
                            key: 'Select',
                            style: { width: '118px' },
                            value: '',
                            field: { value: 'value', label: 'label' },
                            childList: [],
                            clearable: 'clearable',
                            type: 'daterange',
                            callback: 'change',
                            placeholder: '请选择诊室'
                        }
                    ],
                    button: [
                        {
                            key: '登记患者',
                            type: 'primary',
                            has: {
                                name: 'patient-index-guide-create',
                                flag: 'v1/patient/index/guide-create'
                            }
                        }
                    ]
                },
                modal: false,
                options: {
                    disabledDate(date) {
                        return (
                            date && date.valueOf() < Date.now() - 24 * 3600 * 1000
                        );
                    }
                },
                data: [], // 列表数据
                createRules: {
                    user_name: [
                        {
                            required: true,
                            message: '请输入患者姓名',
                            trigger: 'blur'
                        },
                        {
                            required: true,
                            message: '请勿输入空格',
                            pattern: /^\S/,
                            trigger: 'blur'
                        },
                        {
                            required: true,
                            message: '请勿输入空格',
                            pattern: /\S$/,
                            trigger: 'blur'
                        }
                    ],
                    gender: [
                        {
                            required: true,
                            message: '请选择性别',
                            trigger: 'change'
                        }
                    ],
                    clinic_id: [
                        {
                            required: true,
                            message: '请选择诊室',
                            trigger: 'change'
                        }
                    ],
                    mobile: [
                        {
                            required: true,
                            message: '请输入11位手机号',
                            pattern: /^1[3456789]\d{9}$/,
                            trigger: 'blur'
                        }
                    ],
                    age: [
                        {
                            required: true,
                            message: '请输入年龄',
                            type: 'number',
                            trigger: 'change'
                        }
                    ],
                    patient_card_id: [
                        {
                            required: true,
                            message: '请输入患者诊疗号',
                            trigger: 'blur'
                        },
                        {
                            required: true,
                            message: '请勿输入空格',
                            pattern: /^\S/,
                            trigger: 'blur'
                        },
                        {
                            required: true,
                            message: '请勿输入空格',
                            pattern: /\S$/,
                            trigger: 'blur'
                        }
                    ],
                    revisiting_time: [
                        {
                            required: true,
                            type: 'date',
                            message: '请输入到诊时间',
                            trigger: 'change'
                        }
                    ],
                    channel_id: [
                        {
                            required: false,
                            message: '请选择一级来源',
                            trigger: 'change'
                        }
                    ],
                    subdivided_channels_id: [
                        {
                            required: false,
                            message: '请选择二级来源',
                            trigger: 'change'
                        }
                    ],
                    patient_diseases_id: [
                        {
                            required: true,
                            message: '请选择一级病种',
                            trigger: 'change'
                        }
                    ],
                    patient_diseases_child_id: [
                        {
                            required: true,
                            message: '请选择二级病种',
                            trigger: 'change'
                        }
                    ]
                },
                /** *********************/
                year: '',
                options: {
                    disabledDate(date) {
                        return date && date.valueOf() > Date.now();
                    }
                },
                params: {
                    page: 1,
                    pageSize: 10,
                    patient_diseases_id: '',
                    keywords: '',
                    clinic_id: '',
                    patient_card_id: '',
                    channel_id: '',
                    revisiting_stime: new Date(),
                    revisiting_etime: new Date()
                },
                columns: [
                    { title: '基本信息', slot: 'basic', width: 150, fixed: 'left' },
                    {
                        title: '到诊时间',
                        key: 'revisiting_time_str',
                        minWidth: 138
                    },
                    { title: '电话', key: 'mobile', slot: 'mobile', minWidth: 138 },
                    { title: '城市', key: 'city_name', minWidth: 100 },
                    { title: '病种', slot: 'disease', minWidth: 200 },
                    { title: '部门', key: 'department_name', minWidth: 138 },
                    { title: '一级渠道', key: 'source_name', minWidth: 138 },
                    { title: '二级渠道', key: 'child_source_name', minWidth: 138 },
                    { title: '诊疗号', slot: 'patient_card_id', minWidth: 138 },
                    { title: '诊室', slot: 'clinic_id', minWidth: 138 },
                    {
                        title: '状态',
                        key: 'status_name',
                        slot: 'status_name',
                        minWidth: 100
                    }, // , slot: 'status'
                    { title: '操作', slot: 'info', width: 200 }
                ], // 列表表头
                formItem: {
                    user_name: '',
                    gender: '',
                    birthday: '',
                    age: null,
                    channel_id: '',
                    city_id: '',
                    clinic_id: '',
                    patient_card_id: '',
                    remark: '',
                    subdivided_channels_id: '',
                    mobile: '',
                    patient_diseases_id: '',
                    patient_diseases_child_id: ''
                },
                formItems: {
                    id: undefined,
                    user_name: '',
                    city_id: '',
                    clinic_id: '',
                    patient_card_id: '',
                    revisiting_time: new Date()
                },
                daozhenlist: {},
                condition: {
                    diseases: [],
                    clinic: [],
                    source_channel: []
                },
                city_ids: [],
                city_id: [],
                default_city: [
                    {
                        key: '',
                        value: '',
                        label: ''
                    }
                ]
            };
        },
        /* 函数方法集合 */
        methods: {
            cityvalues(city) {
                this.city_ids = city;
                this.formItems.city_id = city.join(',');
            // this.askData();
            },
            cityvalue(city) {
                this.city_id = city;
                this.formItem.city_id = city.join(',');
            // this.askData();
            },
            changechannel() {
                this.formItem.subdivided_channels_id = '';
                for(let item of this.condition.source_channel) {
                    if(this.formItem.channel_id == item.value) {
                        this.source_channellist = item.children;
                    }
                }
            },
            changediseases() {
                this.formItem.patient_diseases_child_id = '';
                for(let item of this.condition.diseases) {
                    if(this.formItem.patient_diseases_id == item.value) {
                        this.diseaseslist = item.children;
                    }
                }
            },
            // 获取病种
            _guidecreateCondition(){
                guidecreateCondition().then(res => {
                    this.patientdiseasesList = res.condition.diseases;
                });
            },
            changechilddiseases(){
                for(let item of this.patientdiseasesList) {
                    if(this.formItem.patient_diseases_id == item.value) {
                        this.childdiseasesList = item.children;
                    }
                }
            },
            /* @函数功能: 初始化 */
            initial() {
                this.funaskData = patientindexguidearrivelist;
                this.funcreate = patientindexguidecreate;
            },
            initials() {
                this.askData();
                this._guidecreateCondition();
            },
            /* @函数功能: 请求数据 */
            askDatas(res) {
                this.disabled = false;
                this.condition = res.condition;
                this.data = res.list;
                this.total = res.total;
                this.default_city[0].key = res.default_city.city_id;
                this.default_city[0].value = res.default_city.city_id;
                this.default_city[0].label = res.default_city.city_name;
                this.searchData.project.forEach(item => {
                    if(item.id === 2) {
                        if(item.childList.length === 0) item.childList = this.condition.diseases;
                    }else if(item.id === 5) {
                        if(item.childList.length === 0) item.childList = this.condition.source_channel;
                    }else if(item.id === 6) {
                        if(item.childList.length === 0)item.childList = this.condition.clinic;
                    }
                });
            },
            guideopenedit() {
                this.optionscity = JSON.parse(JSON.stringify(this.default_city));
                this.openedit(-1);
            },
            remoteMethod(query) {
                if(query !== '') {
                    if(parseFloat(query).toString() !== 'NaN') {
                        query = query.slice(6, query.length); 
                    }
                    this.loadingcity = true;
                    return new Promise(resolve => {
                        setTimeout(() => {
                            patientindexsearchcity({
                                keywords: query
                            }).then(res => {
                                if(res.list && res.list.length > 0) {
                                    const list = res.list.map(item => {
                                        return {
                                            key: `${item.value} ${query}`,
                                            value: item.value,
                                            label: item.label
                                        };
                                    });
                                    this.optionscity = list;
                                }
                                resolve(res.data);
                            });
                            this.loadingcity = false;
                        }, 200);
                    });
                }else {
                    this.optionscity = [];
                }
            },
            dateage(year) {
                if(!year) this.formItem.age = null;
                else {
                    this.formItem.age = dayjs().$y - dayjs(year).$y || 1; 
                }
            },
            inputage(age) {
                let years = dayjs().$y - age;
                this.formItem.birthday = `${years}-01-01`;
            },
            askDatakeyword() {
                this.params.page = 1;
                this.searchData.project.forEach(item => {
                    if(item.id === 3) {
                        this.params.keywords = item.value;
                    }else if(item.id === 1) {
                        let keywording = '';
                        this.searchData.project.forEach(items => {
                            if(items.id === 3) {
                                keywording = items.value;
                            }
                        });
                        if(keywording !== '') {
                            if(JSON.stringify(item.value) !== JSON.stringify(['', ''])) {
                                let timer = [dayjs(item.value[0]).format('YYYY-MM-DD'), dayjs(item.value[1]).format('YYYY-MM-DD')];
                                this.storage.set('guide', timer);
                                item.value = ['', ''];
                                this.params.revisiting_stime = '';
                                this.params.revisiting_etime = '';
                            }
                        }else {
                            if(JSON.stringify(this.storage.get('guide')) !== JSON.stringify(['', ''])) {
                                item.value = this.storage.get('guide');
                            }
                            this.params.revisiting_stime = item.value[0];
                            this.params.revisiting_etime = item.value[1];
                        }
                    // item.value = "";
                    // this.params.revisiting_stime = "";
                    // this.params.revisiting_etime = "";
                    }else if(item.id === 2) {
                        item.value = '';
                        this.params.patient_diseases_id = '';
                    }else if(item.id === 4) {
                        item.value = '';
                        this.params.patient_card_id = '';
                    }
                });
                this.askData();
            },
            askDatakeywords() {
                this.params.page = 1;
                this.searchData.project.forEach(item => {
                    if(item.id === 4) {
                        this.params.patient_card_id = item.value;
                    }else if(item.id === 3) {
                        item.value = '';
                        this.params.keywords = '';
                    }else if(item.id === 1) {
                        let keywording = '';
                        this.searchData.project.forEach(items => {
                            if(items.id === 4) {
                                keywording = items.value;
                            }
                        });
                        if(keywording !== '') {
                            if(JSON.stringify(item.value) !== JSON.stringify(['', ''])) {
                                let timer = [dayjs(item.value[0]).format('YYYY-MM-DD'), dayjs(item.value[1]).format('YYYY-MM-DD')];
                                this.storage.set('guide', timer);
                                item.value = ['', ''];
                                this.params.revisiting_stime = '';
                                this.params.revisiting_etime = '';
                            }
                        }else {
                            if(JSON.stringify(this.storage.get('guide')) !== JSON.stringify(['', ''])) {
                                item.value = this.storage.get('guide');
                            }
                            this.params.revisiting_stime = item.value[0];
                            this.params.revisiting_etime = item.value[1];
                        }
                    // item.value = "";
                    // this.params.revisiting_stime = "";
                    // this.params.revisiting_etime = "";
                    }else if(item.id === 2) {
                        item.value = '';
                        this.params.patient_diseases_id = '';
                    }
                });
                this.askData();
            },
            askDatanow() {
                this.params.page = 1;
                this.searchData.project.forEach(item => {
                    if(item.id === 2) {
                        this.params.patient_diseases_id = item.value;
                    }else if(item.id === 4) {
                        this.params.patient_card_id = item.value;
                    }else if(item.id === 5) {
                        this.params.channel_id = item.value;
                    }else if(item.id === 6) {
                        this.params.clinic_id = item.value;
                    }
                });
                this.askData();
            },
            askDataing() {
                this.searchData.project.forEach(item => {
                    if(item.id === 1) {
                        this.params.revisiting_stime = item.value[0];
                        this.params.revisiting_etime = item.value[1];
                        let timer = ['', ''];
                        if(JSON.stringify(item.value) !== JSON.stringify(['', ''])) {
                            timer = [dayjs(item.value[0]).format('YYYY-MM-DD'), dayjs(item.value[1]).format('YYYY-MM-DD')];
                        }
                        this.storage.set('guide', timer);
                    }
                });
                this.askDatanow();
            },
            /* @函数功能: 打开新增或编辑 */
            handleOpenDrawer(row) {
                let rows = JSON.parse(JSON.stringify(row));
                rows.mobile = rows.mobile.join('');
                this.daozhenlist = rows;
                this.formItems.id = row.id;
                this.formItems.city_id = [row.province_id ? row.province_id : '', row.city_id ? row.city_id : '', row.area_id ? row.area_id : ''];
                this.optionscity = [];
                if(row.city_id) {
                    this.formItems.city_id = row.city_id;
                    this.optionscity = [
                        {
                            key: row.city_id,
                            value: row.city_id,
                            label: row.city_name
                        }
                    ];
                }else {
                    this.optionscity = JSON.parse(
                        JSON.stringify(this.default_city)
                    );
                }
                this.modal = true;
            },
            handleRemove(row) {
                this.$Modal.confirm({
                    title: '撤诊提醒',
                    content: '是否确认撤诊',
                    onOk: () => {
                        patientindexcancelarrive({ id: row.id }).then(() => {
                            this.$Message.success('撤诊成功');
                            this.askData();
                        });
                    }
                });
            },
            handleRemoves(row) {
                this.$Modal.confirm({
                    title: '删除提醒',
                    content: '是否确认删除该条信息？',
                    onOk: () => {
                        patientindexguidedel({ id: row.id }).then(() => {
                            this.$Message.success('删除成功');
                            this.askData();
                        });
                    }
                });
            },
            /* @函数功能: 新增或编辑提交 */
            handleSubmit(name) {
                this.$refs[name].validate(valid => {
                    if(valid) {
                        this.remarksloading = true;
                        let config = JSON.parse(JSON.stringify(this.formItems));
                        config.city_id = config.city_id.split(' ')[0];
                        config.revisiting_time = dayjs(config.revisiting_time).format('YYYY-MM-DD');
                        patientindexarrive(config).then(() => {
                            this.$Message.success('编辑成功');
                            this.handleDrawerCancel(name);
                            this.askData();
                            this.remarksloading = false;
                        }).catch(() => {
                            this.remarksloading = false;
                        });
                    }
                });
            },
            handleSub(row) {
                let params = {
                    id: row.id,
                    clinic_id: row.clinic_id,
                    patient_card_id: row.patient_card_id
                };
                patientindexeditguideuser(params).then(() => {
                    this.$Message.success('编辑成功');
                    this.askData();
                    this.disabled = false;
                    row.is_edit = false;
                });
            },
            /* @函数功能: 取消新增或编辑 */
            handleDrawerCancel(name) {
                this.city_ids = [];
                this.$refs[name].resetFields();
                this.formItems = {
                    id: undefined,
                    user_name: '',
                    city_id: '',
                    clinic_id: '',
                    patient_card_id: '',
                    revisiting_time: new Date()
                };
                this.optionscity = [];
                this.year = '';
                this.formItem = {
                    user_name: '',
                    gender: '',
                    birthday: '',
                    age: null,
                    channel_id: '',
                    city_id: '',
                    clinic_id: '',
                    patient_card_id: '',
                    remark: '',
                    subdivided_channels_id: '',
                    mobile: '',
                    patient_diseases_id: '',
                    patient_diseases_child_id: ''
                };
                this.modal = false;
            },
            /* @函数功能: 清空数据 */
            paramscancel() {
                this.city_id = [];
                this.$refs.formItem.resetFields();
                this.formItems = {
                    id: undefined,
                    user_name: '',
                    city_id: '',
                    clinic_id: '',
                    patient_card_id: '',
                    revisiting_time: new Date()
                };

                this.city_ids = [];
                this.year = '';
                this.formItem = {
                    user_name: '',
                    gender: '',
                    birthday: '',
                    age: null,
                    channel_id: '',
                    city_id: '',
                    clinic_id: '',
                    patient_card_id: '',
                    remark: '',
                    subdivided_channels_id: '',
                    mobile: '',
                    patient_diseases_id: '',
                    patient_diseases_child_id: ''
                };
            },
            paramssubmit() {
                let config = JSON.parse(JSON.stringify(this.formItem));
                config.city_id = config.city_id.split(' ')[0];
                return config;
            }
        }
    };
</script>

<style lang="less" scoped></style>
